package com.restphp.java.utils.http;

import com.google.common.base.Splitter;

import java.util.HashMap;
import java.util.Map;

/**
 * Http常用操作工具类.
 * Created by sofical on 2020/9/27.
 */
public class HttpRequestParam {
    /**
     * 请求参数.
     */
    private Map<String, String> requestParam = new HashMap<>();

    /**
     * construct.
     * @param url 地址.
     */
    public HttpRequestParam(String url) {
        if (!url.contains("?")) {
            return;
        }
        String params = url.substring(url.indexOf("?")+1);
        requestParam = Splitter.on("&").withKeyValueSeparator("=").split(params);
    }

    /**
     * 是否存在参数名.
     * @param name 参数名.
     * @return 判断结果.
     */
    public Boolean contianKey(String name) {
        return requestParam.containsKey(name);
    }

    /**
     * 获取参数值.
     * @param name 参数名.
     * @return 参数值.
     */
    public String get(String name) {
        return requestParam.get(name);
    }
}
